function DOMReady( callback ) {
  
    if ( document.readyState === "complete" ) {
        return setTimeout( callback, 1 );
    }
  
    var loaded = function( doScroll ) {
        if ( document.removeEventListener ) {
            document.removeEventListener( 'DOMContentLoaded', loaded, false );
            window.removeEventListener( 'load', loaded, false );
            loaded = null;
            callback();
        } else if ( document.detachEvent ) {
            if ( document.readyState === "complete" || doScroll === null ) {
                document.detachEvent( 'onreadystatechange', loaded );
                window.detachEvent( 'onload', loaded );
                loaded = null;
                callback();
            }
        }
    }
  
    if ( document.addEventListener ) {
        document.addEventListener( "DOMContentLoaded", loaded, false );
        window.addEventListener( "load", loaded, false );
    } else if ( document.attachEvent ) {
        document.attachEvent( "onreadystatechange", loaded );
        window.attachEvent( "onload", loaded );
  
        var toplevel = false;
        try {
            toplevel = window.frameElement == null;
        } catch( _e_ ) {}
  
        if ( document.documentElement.doScroll && toplevel ) {
            var check = function() {
                if ( !loaded ) return;
                try {
                    document.documentElement.doScroll( "left" );
                } catch( _e_ ) {
                    setTimeout( check, 0 );
                    return;
                }
                loaded( null );
            }
            check();
        }
    }
}